using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using WalkingTec.Mvvm.Core;

namespace HengTong.Model.Db.SupplyChain.Material;

/// <summary>
/// 系统物料属性
/// 记录物料的各种属性信息，如颜色、尺寸、材质等
/// 相同物料可以有多个属性
/// 属性名称会重复, 但同一物料的相同属性名称只能有一个
/// 物料+属性名称+值是唯一组合
/// </summary>
[Display(Name = "物料属性", Description = "系统物料的属性信息")]
public class SysMaterialAttribute : BasePoco
{
    /// <summary>
    /// 属性名称
    /// </summary>
    [Display(Name = "属性名称", Description = "物料属性的名称")]
    [StringLength(64, ErrorMessage = "{0}长度不能超过{1}")]
    public string Name { get; set; }
    
    /// <summary>
    /// 属性值列表
    /// </summary>
    [Display(Name = "属性值列表", Description = "该物料属性的所有可选值")]
    public List<SysMaterialAttributeValue> Values { get; set; }
    
    /// <summary>
    /// 是否关键属性, 关键属性会生成SKU编码, 非关键属性仅用于采购和领用等辅助识别
    /// </summary>
    [Display(Name = "是否关键属性", Description = "关键属性会生成SKU编码, 非关键属性仅用于采购和领用等辅助识别")]
    public bool IsKeyAttribute { get; set; }
    
    /// <summary>
    /// 物料ID
    /// </summary>
    [Display(Name = "物料ID", Description = "关联的物料唯一标识")]
    public Guid? MaterialId { get; set; }
    
    /// <summary>
    /// 关联的物料对象
    /// </summary>
    [Display(Name = "物料", Description = "关联的物料对象")]
    public SysMaterial Material { get; set; }
    
    /// <summary>
    /// 备注
    /// </summary>
    [Display(Name = "备注", Description = "计量单位组的备注信息")]
    [StringLength(256)]
    public string Remark { get; set; }

    /// <summary>
    /// 排序字段
    /// </summary>
    [Column(TypeName = "decimal(8,2)")]
    [Display(Name = "排序", Description = "物料属性的排序字段")]
    public decimal Order { get; set; } = 20m;
}

/// <summary>
/// 物料属性值
/// 记录物料属性的具体取值，如颜色属性的"红色"、"蓝色"等
/// </summary>
[Display(Name = "物料属性值", Description = "物料属性的具体取值")]
public class SysMaterialAttributeValue : BasePoco
{
    /// <summary>
    /// 关联的属性对象
    /// </summary>
    [Display(Name = "属性", Description = "关联的物料属性对象")]
    public SysMaterialAttribute Attribute { get; set; }
    
    /// <summary>
    /// 属性ID
    /// </summary>
    [Display(Name = "属性ID", Description = "关联的物料属性唯一标识")]
    public Guid? AttributeId { get; set; }
    
    /// <summary>
    /// 属性值
    /// </summary>
    [Display(Name = "属性值", Description = "物料属性的具体取值")]
    [StringLength(128)]
    public string Value { get; set; }

    /// <summary>
    /// 库存数量(不映射到数据库)
    /// </summary>
    [Display(Name = "库存数量", Description = "该属性值对应的库存数量")]
    [NotMapped]
    public decimal InStock { get; set; }
}